package com.xxx.video.mine.activitys;

import android.os.Bundle;

import androidx.recyclerview.widget.GridLayoutManager;

import com.xxx.video.R;
import com.xxx.video.commen.activitys.BaseActivity;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.dbs.beans.DownloadHistoryBean;
import com.xxx.video.commen.utils.ListUtils;
import com.xxx.video.commen.utils.StatusBarUtil;
import com.xxx.video.commen.views.recyclerviews.RefreshRecyclerView;
import com.xxx.video.main.activitys.VideoDetailsActivity;
import com.xxx.video.mine.adapters.DownloadManagementListAdapter;
import com.xxx.video.mine.presenters.DownloadManagementPresenter;
import com.xxx.video.mine.presenters.IDownloadManagementView;

import java.util.List;

import butterknife.BindView;

public class DownloadManagementActivity extends BaseActivity<DownloadManagementPresenter>
        implements IDownloadManagementView, BaseRecycleViewAdapter.OnItemClickListener<DownloadHistoryBean>,
        RefreshRecyclerView.OnRecyclerViewRefreshOrLoadMoreListener {

    @BindView(R.id.rcv_download_management_list)
    RefreshRecyclerView rcvDownloadManagementList;
    /**
     * page
     */
    private int page = 1;
    private DownloadManagementListAdapter mDownloadManagementListAdapter;

    @Override
    public void initToolbarData() {
        super.initToolbarData();
        showActionBar();
        StatusBarUtil.getInstance().setStatusBarTransparent(this, true);
        setIsShowActionbarLine(true);
        setActionBarTitle(R.string.title_download_management_activity);
    }

    @Override
    protected DownloadManagementPresenter createPresenter() {
        return new DownloadManagementPresenter(this, this);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_download_management;
    }

    @Override
    public void initData(Bundle extras) {
        getPresenter().getDownloadList(page);
    }

    @Override
    public void showRootLayoutStatus(int status) {
        showLayoutStatus(status);
    }

    @Override
    public void initDownloadManagementList(List<DownloadHistoryBean> downloadHistoryBeanList) {
        rcvDownloadManagementList.resetState();
        showRootLayoutStatus(1);
        if (mDownloadManagementListAdapter == null) {
            rcvDownloadManagementList.setLayoutManager(new GridLayoutManager(this, 2));
            mDownloadManagementListAdapter = new DownloadManagementListAdapter(this);
            mDownloadManagementListAdapter.setOnItemClickListener(this);
            rcvDownloadManagementList.setAdapter(mDownloadManagementListAdapter);
            rcvDownloadManagementList.setOnRecyclerViewRefreshOrLoadMoreListener(this);
        }
        if (page == 1) {
            mDownloadManagementListAdapter.setData(downloadHistoryBeanList);
            if (ListUtils.isEmpty(downloadHistoryBeanList)) {
                showRootLayoutStatus(2);
            }
        } else {
//            mDownloadManagementListAdapter.addData(likeRecordBean.page.list);
        }
    }


    @Override
    public void onItemClick(DownloadHistoryBean listBean, int position, int type) {
        startVideoDetailsActivity(listBean.fId);
    }

    @Override
    public void startVideoDetailsActivity(String id) {
        Bundle bundle = new Bundle();
        bundle.putString("Id", id);
        bundle.putBoolean("IsDownload", true);
        intent2Activity(VideoDetailsActivity.class, bundle);
    }

    @Override
    public void onRecyclerviewRefresh() {
        page = 1;
        getPresenter().getDownloadList(page);
    }

    @Override
    public void onRecyclerviewLoadMore() {
        page++;
        getPresenter().getDownloadList(page);
    }
}
